﻿
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="pgAdmAM.aspx.cs" Inherits="EGuayas.Web.Auditoria.Admin.Monitoreo.pgAdmAM" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title><link  href="~/Resources/css/Style.css"  rel="stylesheet" /><!-- Load Ext JS --> <script src="../../../Resources/js/Global.js"></script>
</head>
<body>
    <ext:ResourceManager ID="ResourceManager1" runat="server"></ext:ResourceManager>
    <ext:Viewport ID="Viewport1" runat="server" Layout="BorderLayout">
        <Items>
            <%-- Hidden almacena IdPageSession  --%>
            <ext:Hidden Text="" ID="hddIdSelect" runat="server" ></ext:Hidden>            
            <ext:Panel ID="Panel1" runat="server"  BodyPadding="6"   Collapsible="true" Split="true"  Region="North"
                TitleCollapse="false" ButtonAlign="Center" Border="false">
                <Items>
                    <ext:Panel ID="panC1" runat="server" Layout="ColumnLayout" Border="false" >
                        <Items>
                            <ext:Panel ID="panC1Col1" runat="server" ColumnWidth=".33" Border="false">
                                <Items>
                                    <ext:ComboBox ID="cbbProvincia" runat="server" FieldLabel="Provincia" ValueField="Id" DisplayField="Nombre">
                                        <Store>
                                            <ext:Store runat="server" ID="stoProvincia">
                                                <Model>
                                                    <ext:Model ID="Model3" runat="server" IDProperty="Id">
                                                        <Fields>
                                                            <ext:ModelField Name="Id"></ext:ModelField>
                                                            <ext:ModelField Name="Nombre"></ext:ModelField>
                                                        </Fields>
                                                    </ext:Model>
                                                </Model>
                                            </ext:Store>
                                        </Store>
                                        <Triggers>
                                            <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                        </Triggers>
                                        <Listeners>
                                            <Select Handler="this.getTrigger(0).show();" />
                                            <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                            <TriggerClick Handler="if (index == 0) { 
                                           this.clearValue(); 
                                           this.getTrigger(0).hide();
                                       }" />
                                        </Listeners>
                                        <DirectEvents>
                                            <Select OnEvent="cbbProvincia_Select">
                                                <ExtraParams>
                                                    <ext:Parameter Name="Id" Value="#{cbbProvincia}.getValue()" Mode="Raw"/>
                                                </ExtraParams>
                                                <EventMask ShowMask="True"></EventMask>
                                            </Select>
                                        </DirectEvents>
                                    </ext:ComboBox>
                                    <ext:TextField ID="txtCodigo" runat="server" FieldLabel="Código"></ext:TextField>
                                </Items>
                            </ext:Panel>
                            <ext:Panel ID="panC1Col2" runat="server" ColumnWidth=".33" Border="false">
                                <Items>
                                    <ext:ComboBox ID="cbbCanton" runat="server" FieldLabel="Cantón" ValueField="Id" DisplayField="Nombre">
                                        <Store>
                                            <ext:Store runat="server" ID="stoCanton">
                                                <Model>
                                                    <ext:Model ID="Model4" runat="server" IDProperty="Id">
                                                        <Fields>
                                                            <ext:ModelField Name="Id"></ext:ModelField>
                                                            <ext:ModelField Name="Nombre"></ext:ModelField>
                                                        </Fields>
                                                    </ext:Model>
                                                </Model>
                                            </ext:Store>
                                        </Store>
                                        <Triggers>
                                            <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                        </Triggers>
                                        <Listeners>
                                            <Select Handler="this.getTrigger(0).show();" />
                                            <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                            <TriggerClick Handler="if (index == 0) { 
                                           this.clearValue(); 
                                           this.getTrigger(0).hide();
                                       }" />
                                        </Listeners>
                                        <DirectEvents>
                                            <Select OnEvent="cbbCanton_Select">
                                                <ExtraParams>
                                                    <ext:Parameter Name="Id" Value="#{cbbCanton}.getValue()" Mode="Raw"/>
                                                </ExtraParams>
                                                <EventMask ShowMask="True"></EventMask>
                                            </Select>
                                        </DirectEvents>
                                    </ext:ComboBox>
                                    <ext:TextField ID="txtNombre" runat="server" FieldLabel="Nombre"></ext:TextField>
                                </Items>
                            </ext:Panel>
                            <ext:Panel ID="panC1Col3" runat="server" ColumnWidth=".33" Border="false">
                                <Items>
                                    <ext:ComboBox ID="cbbParroquia" runat="server" FieldLabel="Parroquia" ValueField="Id" DisplayField="Nombre">
                                        <Store>
                                            <ext:Store runat="server" ID="stoParroquia">
                                                <Model>
                                                    <ext:Model ID="Model5" runat="server" IDProperty="Id">
                                                        <Fields>
                                                            <ext:ModelField Name="Id"></ext:ModelField>
                                                            <ext:ModelField Name="Nombre"></ext:ModelField>
                                                        </Fields>
                                                    </ext:Model>
                                                </Model>
                                            </ext:Store>
                                        </Store>
                                        <Triggers>
                                            <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                        </Triggers>
                                        <Listeners>
                                            <Select Handler="this.getTrigger(0).show();" />
                                            <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                            <TriggerClick Handler="if (index == 0) { 
                                           this.clearValue(); 
                                           this.getTrigger(0).hide();
                                       }" />
                                        </Listeners>
                                    </ext:ComboBox>
                                </Items>
                            </ext:Panel>
                        </Items>
                    </ext:Panel>
                </Items>
                <Buttons>
                    <ext:Button ID="btnBuscar" runat="server" Text="Buscar">
                        <DirectEvents>
                            <Click OnEvent="btnBuscar_Click">
                                <ExtraParams>
                                    <ext:Parameter Name="Codigo" Value="#{txtCodigo}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="Nombre" Value="#{txtNombre}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="ProvinciaId" Value="#{cbbProvincia}.getValue()==null?'':#{cbbProvincia}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="CantonId" Value="#{cbbCanton}.getValue()==null?'':#{cbbCanton}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="ParroquiaId" Value="#{cbbParroquia}.getValue()==null?'':#{cbbParroquia}.getValue()" Mode="Raw"/>
                                </ExtraParams>
                                <EventMask ShowMask="True"></EventMask>
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                </Buttons>
            </ext:Panel>
            <ext:Panel  runat="server" Split="true"    Region="Center" 
                TitleCollapse="true">
                <Items>
                        <ext:GridPanel runat="server" ID="gpnAuditoria"  Header="false"  Height="190" Title="Expedientes de Licencias para control y seguimiento" Region="East">
                              <Store>
                                <ext:Store runat="server" ID="stoExpedienteAud">
                                <Model>
                                <ext:Model ID="Model2" runat="server" IDProperty="Id" >
                                <Fields>
                                    <ext:ModelField Name="Id"/>
                                    <ext:ModelField Name="ExpedienteId" />
                                    <ext:ModelField Name="Nombre"/>
                                    <ext:ModelField Name="Regulado"/>
                                    <ext:ModelField Name="Descripcion"/>
                                    <ext:ModelField Name="Estado"/>
                                    <ext:ModelField Name="Fase"/>
                                    

                                </Fields>
                            </ext:Model>
                                </Model>
                            </ext:Store>
                            </Store>
                            <ColumnModel>
                                <Columns>
                                    <ext:Column ID="Column1"  runat="server" Text="Nombre" Flex="1" DataIndex="Nombre" />
                                 
                       
                                    <ext:Column ID="Column2" runat="server" Text="Regulado" DataIndex="Regulado" Width="120" />
                                    <ext:Column ID="Column3" runat="server" Text="Descripción" DataIndex="Descripcion" Width="150" />
                                    <ext:Column ID="Column4" runat="server" Text="Estado" DataIndex="Estado" Width="80" />
                                    <ext:Column ID="Column5" runat="server" Text="Fase" DataIndex="Fase" Width="80" />
                                       <ext:Column ID="Column13" runat="server"  Width="70" Align="Right" RightCommandAlign="false"  >
                                                    <Commands>
                                                        <ext:ImageCommand CommandName="CmdDocAsoc" Icon="PageWhiteCopy"  ToolTip-Text="Ver documentos de expedientes"/>                                                           
                                                    </Commands>
                                                         <%-- <PrepareCommand Fn="pgFnAdmin.PrepareDocAsociados" />--%>
                                                    <Listeners> 
                                                            <Command Handler="AppGlobalJs.mostrarVentanaUrl('../../../Auditoria/admin/pgDocGlobalAuditoria.aspx?Id='+record.data.ExpedienteId,record.data.Nombre);" />                                                         
                                                    </Listeners>
                                  </ext:Column> 
                                </Columns>
                            </ColumnModel>
                            <DirectEvents>
                                <Select OnEvent="gpnAuditoria_Select" Before="App.hddIdSelect.setValue(record.data.Id);">
                                    <EventMask ShowMask="True"></EventMask>
                                    <ExtraParams>
                                        <ext:Parameter Name="Id" Value="record.data.Id" Mode="Raw"/>
                                    </ExtraParams>
                                </Select>
                            </DirectEvents>
                        </ext:GridPanel>
                        <ext:GridPanel runat="server" ID="gpnAuditoriaMonitoreo"  Height="230" Region="West">
        <TopBar>
            <ext:Toolbar ID="Toolbar1" runat="server">
                <Items>
                    <ext:Label ID="Label1" runat="server" Text="Listado de Monitoreos"></ext:Label>
                    <ext:ToolbarFill ID="ToolbarFill1" runat="server"/>
                    <ext:Button ID="btnNuevaAC" runat="server" Text="Nueva" Icon="ApplicationFormAdd">
                        <Listeners>
                            <Click Handler="pgFnAdmin.ShowNuevoExpediente();"></Click>
                        </Listeners>
                    </ext:Button>
                </Items>
            </ext:Toolbar>
        </TopBar>
                <Store>
                    <ext:Store runat="server" ID="stoAM">
                        <Model>
                    <ext:Model ID="Model1" runat="server" IDProperty="Id" >
                        <Fields>
                            <ext:ModelField Name="Id"/>
                            <ext:ModelField Name="ExpedienteId" />
                            <ext:ModelField Name="ExpedienteAuditoriaId" />
                            <ext:ModelField Name="Nombre"/>
                            <ext:ModelField Name="Promotor"/>
                            <ext:ModelField Name="Descripcion"/>
                            <ext:ModelField Name="Estado" />
                            <ext:ModelField Name="FechaInicio"  Type="Date"/>
                            <ext:ModelField Name="FechaFin" Type="Date"/>
                           <ext:ModelField Name="EstadoFase" />
                             <ext:ModelField Name="Alias" />

                        </Fields>
                    </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel>
                    <Columns>
                       <ext:Column ID="Column6"  runat="server" Text="Auditoria" Flex="1" DataIndex="Nombre" />
                        <ext:Column ID="Column7"  runat="server" Text="Nombre" Flex="1" DataIndex="Alias" />
                       
                       
                        <ext:Column runat="server" Text="Promotor" DataIndex="Promotor" Width="120" />
                        <ext:Column runat="server" Text="Descripción" DataIndex="Descripcion" Width="150" />
                       <ext:Column runat="server" Text="Estado" Width="80" DataIndex="EstadoFase">
                          <%--   <Renderer Fn="pgFnAdmin.FormatEstado" />--%>
                        </ext:Column>
                        <ext:DateColumn runat="server"  Text="Fecha Inicio"    DataIndex ="FechaInicio"   />
                        <ext:DateColumn runat="server"  Text="Fecha Fin"       DataIndex ="FechaFin"   />
                         <ext:CommandColumn ID="CommandColumn1"  runat="server" Width="80" Text="Editar" >
	                        <Commands>
	                        <ext:GridCommand Icon="ApplicationFormEdit" CommandName="EditarProceso">
		                        <ToolTip Text="Editar Monitoreo" />
	                        </ext:GridCommand>
	                      
                        </Commands>
	                        <Listeners>
		                        <Command Handler="pgFnAdmin.UpdateNuevoExpediente(record);"></Command>
	                        </Listeners>
                        </ext:CommandColumn> 
                        <ext:CommandColumn  runat="server" Width="80" >
                            <Commands>
                            <ext:GridCommand Icon="TableGo" CommandName="VerProceso">
                                <ToolTip Text="Ver Monitoreo" />
                            </ext:GridCommand>
                            <ext:CommandSeparator />
                        </Commands>
                            <Listeners>
                                <Command Handler="pgFnAdmin.LinkExpediente(record);"></Command>
                            </Listeners>
                        </ext:CommandColumn>
                        
                    </Columns>
                </ColumnModel>
                <Plugins>
                    <ext:RowExpander ID="RowExpander1" runat="server">
                    <Renderer Handler="if (record.get('Id')  === '')  { return false; }" />
                    <Loader ID="Loader1" runat="server" Url="~/Auditoria/admin/wsGetData.asmx/GetSubAud" Mode="Component">
                        <LoadMask ShowMask="true" />
                        <AjaxOptions Json="true" />
                        <Params>
                            <ext:Parameter Name="id" Value="this.record.data.Id" Mode="Raw" />
                            <ext:Parameter Name="table" Value="INFDOCAUDMON" Mode="Value" />
                            <ext:Parameter Name="link" Value="ADMIN_MON" Mode="Value" />
                        </Params>
                    </Loader>
                    </ext:RowExpander>
                    <ext:BufferedRenderer ID="BufferedRenderer1" runat="server" />
               </Plugins> 
            </ext:GridPanel>
                </Items>
            </ext:Panel>
         </Items>
    </ext:Viewport>
    <ext:XScript ID="XScript1" runat="server">
        <script type="text/javascript">         

            var pgFnAdmin = new Object();
            pgFnAdmin.winUrl = null;
            pgFnAdmin.FormatEstado = function (value) {
                var template = '<span>{0}</span>';
                return Ext.String.format(template, (value == "N") ? "No" : "Si", value);

            };
            //Cerrar ventana creada
            pgFnAdmin.BeforeClose = function (win,namewin) {
                try{
                        Ext.Msg.confirm('Aviso', 'Desea cerrar ventana <b>Monitoreo de '+namewin+'</b>?', function (btn) {
                            if (btn == 'yes') 
                            { 
                                win.forceHide();
                                return true;
                            }
                        });
                        return false;
                } catch (jsbug) {
                    AppGlobalJs.showBug("pgFnAdmin.BeforeClose :" + jsbug)
                }
            };
            pgFnAdmin.ClosePgAdmGlobal = function () {
               
                        App.direct.DataBindAuditoriaMonitoreo(#{hddIdSelect}.getValue(),{
                            success: function (result) {
                      
                            },
                            eventMask: {
                                showMask: true,
                                minDelay: 500
                            }
                        });
                   
            };
            App.CloseNuevoExpediente =  function () {
                try 
                {
                    if ( pgFnAdmin.winUrl  !=null)
                    {
                        pgFnAdmin.winUrl.close();
                        pgFnAdmin.winUrl=null;
                    }
                } catch (jsbug) {
                    AppGlobalJs.showBug("App.CloseNuevoExpediente :" + jsbug)
                }
                      
            };
            pgFnAdmin.ShowNuevoExpediente = function () {
                var objSelect = App.gpnAuditoria.getRowsValues({ selectedOnly: true });
                if (objSelect.length != 0) {
                    var rowSelect = objSelect[0];
                    pgFnAdmin.winUrl = AppGlobalJs.mostrarVentanaUrl('pgNuevoExpediente.aspx?evt=NUEVO&exp_id=' + rowSelect.ExpedienteId + '&exa_id=' + rowSelect.Id+"&estadoFase="+rowSelect.EstadoFase, 'Nuevo Monitoreo de ' + rowSelect.Nombre, '#ApplicationViewTile');
                    pgFnAdmin.winUrl.addListener('close', function (el) { pgFnAdmin.ClosePgAdmGlobal(rowSelect.Nombre); el.destroy(); });
          
                }

            };
            pgFnAdmin.UpdateNuevoExpediente = function (record) {
                pgFnAdmin.winUrl =AppGlobalJs.mostrarVentanaUrl('pgNuevoExpediente.aspx?evt=MODIFICAR&mon_id='+record.data.Id+'&exp_id='+record.data.ExpedienteId+"&estadoFase="+record.data.EstadoFase,'Modificar Monitoreo de ' +record.data.Nombre,'#ApplicationFormAdd');
                pgFnAdmin.winUrl.addListener('close', function (el) { pgFnAdmin.ClosePgAdmGlobal(record.data.Nombre); el.destroy(); });       
            };
            pgFnAdmin.LinkExpediente = function (record) {
                pgFnAdmin.winUrl =AppGlobalJs.mostrarVentanaUrl('pgAMonit.aspx?mon_id='+record.data.Id+'&exp_id='+record.data.ExpedienteId+'&exa_id='+record.data.ExpedienteAuditoriaId+"&estadoFase="+record.data.EstadoFase ,'Monitoreo de ' + record.data.Nombre,'#ApplicationFormAdd');
                pgFnAdmin.winUrl.addListener('close', function (el) { pgFnAdmin.ClosePgAdmGlobal(); el.destroy(); });    
                pgFnAdmin.winUrl.addListener('beforehide', function (el) { return pgFnAdmin.BeforeClose(el,record.data.Nombre);});
            };
            /*
           //
            pgFnAdmin.PrepareDocAsociados = function (grid, command, record, row) {
               try
               {
                   if (command.command == 'CmdDocAsoc')
                   {
                     
                       var rolCode=#{hdRol}.getValue();
                       if (rolCode != 'PROMOTOR') {
                          
                           command.hidden = false;
                           command.hideMode = 'visibility';
                       }
                       else
                       {
                           command.hidden = true;
                           command.hideMode = 'display';
                       }


                   }

               } catch (jsbug) {
                   AppGlobalJs.showBug("pgFnAdmin.PrepareDocAsociados : " + jsbug);
               }
           };
           */
        </script>
    </ext:XScript>
</body>
</html>
